//
//  ALPS_LeftLockerController.m
//  Alps
//
//  Created by dllo on 16/6/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_LeftLockerController.h"
#import "ALPS_TSearchViewController.h"
#import "MBProgressHUD.h"
@interface ALPS_LeftLockerController ()<UITableViewDelegate, UITableViewDataSource>

/** 背景图 */
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UITableView *tableView;


@end

@implementation ALPS_LeftLockerController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 背景图
    self.view.backgroundColor = [UIColor orangeColor];
    self.imgView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    _imgView.image = [UIImage imageNamed:@"IMG_0824"];
    self.imgView.userInteractionEnabled = YES;
    [self.view addSubview:_imgView];
    
     //创建tableView
    [self createTableView];
    
}

#pragma mark -- UI创建tableView
- (void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, ScreeHeight * 0.25, ScreeWidth * 0.66, ScreeHeight * 0.5)];
    [self.imgView addSubview:_tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO; // 设置不可滑动
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = [UIColor clearColor];
    
    // 注册
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"leftClockerCell"];
}

#pragma mark -- 代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"leftClockerCell"];
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.font = [UIFont systemFontOfSize:19];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    switch (indexPath.row)
    {
        case 0:
            cell.textLabel.text = @" ❤️  我的收藏";
            break;
        case 1:
            cell.textLabel.text = @" 🌙  夜间模式";
            break;
        case 2:
        {
            NSString *cache = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
            NSString *tempString = [NSString stringWithFormat:@"(%.1lfM)", [WSSFileManager getSizeWithFilePath:cache] / (1024*1024.0)];
            cell.textLabel.text = [NSString stringWithFormat:@" 📱  清理缓存%@", tempString];
        }
            break;
        case 3:
            cell.textLabel.text = @" 👮  关于我们";
            break;
        case 4:

            break;
            
        default:
            break;
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    switch (indexPath.row)
    {
        case 0:
        {
#warning (1)通知第一步:发消息,设置好通知中心的名字,便于其他界面接收消息
            [[NSNotificationCenter defaultCenter] postNotificationName:@"推出收藏夹" object:[UIColor orangeColor]];
        }
            break;
        case 1:
        {
            // 夜间模式通知中心
            [[NSNotificationCenter defaultCenter] postNotificationName:@"夜间模式" object:nil];
        }
            break;
        case 2:
        {
            NSString *cache = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
            NSString *tempString = [NSString stringWithFormat:@"当前缓存共%.1lfM 是否清除缓存", [WSSFileManager getSizeWithFilePath:cache] / (1024*1024.0)];
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:tempString preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *action = [UIAlertAction actionWithTitle:@"清除" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                [WSSFileManager clearDiskWithFilePath:cache];
                [self.tableView reloadData];
                
            }];
            UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            [alertController addAction:action];
            [alertController addAction:actionCancel];
            [self showDetailViewController:alertController sender:nil];
        }
            
            break;
        case 3:
            break;
        case 4:
            
            break;
            
        default:
            break;
    }
    
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
